<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>付款计划</title>
</head>
<body>
		<style type="text/css">
.step {
	margin-top: 20px;
}
</style>
	<script type="text/javascript">
		$(function() {
			$("#zj-pp-zj-datagrid")
					.datagrid(
							{
								fit : true,
								border : false,
								toolbar : '#zj-pt-tb',
								pageSize : 9,
								pageList : [5,8,9,10,15,20],
								fitColumns : true,
								url : 'getAllPP',
								method : 'get',
								singleSelect : false,
								pagination : true,
								columns : [ [
										{
											field : 'cpt',
											width : 1,
											checkbox : true
										},
										{
											field : 'ppId',
											title : 'ID',
											width : 1
										},
										{
											field : 'ppCusName',
											title : '供应商',
											width : 2
										},
										{
											field : 'ppCaiName',
											title : '采购单',
											width : 2
										},
										{
											field : 'ppTime',
											title : '计划付款日期',
											width : 2,
											formatter : function(value, row,
													index) {
												if (value) {
													var date = new Date(value);
													var y = date.getFullYear();
													var m = date.getMonth() + 1;
													var d = date.getDate();
													return y + '-' + m + '-'
															+ d;
												}
											}
										},
										{
											field : 'ppMoney',
											title : '金额',
											width : 1,
											formatter : function(value, row,
													index) {
												return "￥" + value;
											}
										},
										{
											field : 'ppPeriod',
											title : '期次',
											width : 1
										},
										{
											field : 'ppMan',
											title : '负责人',
											width : 1
										},
										{
											field : 'ppState',
											title : '状态',
											width : 2
										},
										{
											field : 'bb',
											width : 4,
											title : '操作',
											formatter : function(value, row,
													index) {
												var btn = '<a class="zj-pt-edit" onclick="editPt('
														+ row.ppId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
														var btn2 = '<a class="zj-pt-delete" onclick="deletePp('
															+ row.ppId
															+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
														return btn+btn2;
											}
										} ] ],
								onLoadSuccess : function(data) {
									$('.zj-pt-edit').linkbutton({
										text : '编辑',
										plain : true,
										iconCls : 'icon-edit'
									});
									$('.zj-pt-delete').linkbutton({
										text : '删除',
										plain : true,
										iconCls : 'icon-cut'
									});
								},
								rowStyler : function(index, row) {
									return 'height:30px';
								}
							});

			$("#zj_pt_list_all").linkbutton({
				onClick : function() {
					$("#zj-pp-zj-datagrid").datagrid({
						pageNumber : 1,
						url : 'getAllPP'
					});
					$("#zj-pp-zj-datagrid").datagrid("reload");
				}
			});
			
			$("#zj_btn_pt_add").linkbutton({
				onClick : function() {
					$("#zj-pt-zj-dg").dialog({
						title : '新建付款计划',
						href2:'addPp'
					});
					$("#zj-pt-add-form").form("clear");
					//$("#zj-back-record-form-cus").textbox({readonly:false})
					$("#zj-pt-zj-dg").dialog("open");
				}
			});
		});

		function deletePp(ppId) {
			$.messager.confirm('提示', '确定要删除吗？', function(v) {
				if (v) {
					$.getJSON('deletepp', {
						ppId:ppId
					}, function(obj) {
						if (obj.success) {
							$("#zj-pp-zj-datagrid").datagrid("reload");
						} else {
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
						}
					});
				}
			});
		}
		function editPt(ppId){
			$("#zj-pt-zj-dg").dialog({
				title : '编辑付款计划',
				href2:'editPp'
			});
			$("#zj-pt-add-form").form('load',
					'getPpById?ppId=' + ppId);
			//$("#zj-back-record-form-cus").textbox({readonly:true})
			$("#zj-pt-zj-dg").dialog("open");
		}
	</script>
	<div id="zj-pt-tb">
		<a id="zj_btn_pt_add" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">添加</a><a
			id="zj_pt_list_all" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a>
	</div>
	<table id="zj-pp-zj-datagrid" class="easyui-datagrid"></table>
	<div id="zj-pt-zj-dg" class="easyui-dialog"
		style="width: 455px; height: 470px;"
		data-options="iconCls:'icon-save',closed:true,resizable:true,modal:true,buttons:[{
				text:'保存',
				iconCls:'icon-ok',
				handler:function(){
				var row = $('#zj-pp-zj-datagrid').datagrid('getSelected');
				alert($('#zj-pt-zj-dg').dialog('options').href2)
					$('#zj-pt-add-form').form({
							url:$('#zj-pt-zj-dg').dialog('options').href2,
							method:'post',
						onSubmit:function(params){
						if (row != null) {
						params.ppId = row.ppId;
						}
							return $(this).form('validate');
						},
						success:function(v){
						var obj = eval('('+v+')');
							if(obj.success){
								$('#zj-pp-zj-datagrid').datagrid('reload');
							}else{
							$.messager.alert('提示', '操作失败,原因：' + obj.message);
							}
							$('#zj-pt-zj-dg').dialog('close');
						}	
					}).submit();
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
				$('#zj-back-record-dialog').dialog('close');
				}
			}]">
		<form id="zj-pt-add-form" method="post">
			<input  id="zj-pp-brid" class="easyui-textbox"  name="ppCaiId"> 
			<div class="step">
				<input id="zj-pp-form-purchase" name="ppCaiName"
					class="easyui-textbox"
					data-options="editable:true,buttonText:'选择采购单',required:true,labelAlign:'right',label:' ',labelWidth:'90',width:320">
			</div>
			<div class="step">
				<input  id="zj-pp-brid2" type="hidden" class="easyui-textbox" name="ppCusId"> 
				<input id="zj-pp-form-cus" name="ppCusName"
					class="easyui-textbox"
					data-options="editable:false,buttonText:'选择供应商',required:true,labelAlign:'right',label:' ',labelWidth:'82',width:300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-pp-form-cus').textbox('setValue', row.custName);
							$('#zj-pp-form-cus').textbox('setText', row.custName);
							$('#zj-pp-brid2').textbox('setValue',row.custId);
						});		
					}">
			</div>
			
			<div class="step">
				<input class="easyui-datebox"
					data-options="required:true,labelAlign:'right',label:'计划付款日期',
					width:300, labelWidth:95"
					name="ppTime">
			</div> 
			
			<div class="step">
				<select class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',required:true,label:'期次',
					width:280, labelWidth:90"
					name="ppPeriod">
					<option disabled selected value=''></option>
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
					<option value="6">6</option>
					<option value="7">7</option>
					<option value="8">8</option>
					<option value="9">9</option>
					<option value="10">10</option>
					<option value="11">11</option>
					<option value="12">12</option>
				</select>
			</div>
			
			<div class="step">
				<input class="easyui-numberbox" name="ppMoney"
					data-options="min:0,precision:2,labelAlign:'right',required:true,label:'金额',
							width:220, labelWidth:90">
			</div>
			<div class="step">
				<select class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',required:true,label:'状态',
					width:280, labelWidth:90"
					name="ppState">
					<option disabled selected value=''></option>
					<option value="未付">未付</option>
					<option value="已付">已付</option>
				</select>
			</div>
			
			<div class="step">
				<input id="zj-form-pt-owner" name="ppMan"
					class="easyui-textbox"
					data-options="editable:false,buttonText:'负责人', label:' ', labelWidth:'90', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-form-pt-owner').textbox('setValue', row.custName);
							$('#zj-form-pt-owner').textbox('setText', row.custName);
						});
					}">
			</div>
		</form>
	</div>
</body>
</html>